<style>
    .xxpayPopupDiv .layui-form-label {
        width:15% !important;
        margin-left:1%;
    }
    .xxpayPopupDiv .layui-input-inline {
        width: 33% !important;
        margin-top: 0px;
    }
</style>
<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-tab layui-tab-brief">
      <div class="layui-tab-content">
          <div class="layui-form layui-form-pane" >

              <div class="layui-form-item">
                  <label class="layui-form-label">账户名</label>
                  <div class="layui-input-inline">
                      <input type="text" id="accountName" disabled="disabled" class="layui-input">
                  </div>
                  <label class="layui-form-label">账户号(银行卡号)</label>
                  <div class="layui-input-inline">
                      <input type="text" id="accountNo" disabled="disabled" class="layui-input">
                  </div>
              </div>

              <div class="layui-form-item">
                  <label class="layui-form-label">打款金额(元)</label>
                  <div class="layui-input-inline">
                      <input type="text" id="remitAmount" disabled="disabled" class="layui-input">
                  </div>
                  <label class="layui-form-label">代付手续费(元)</label>
                  <div class="layui-input-inline">
                      <input type="text" id="fee" disabled="disabled" class="layui-input">
                  </div>
              </div>

              <div class="layui-form-item">
                  <button id="showMoreBtn" class="layui-btn layui-btn-normal" style="width: 100%; background-color: #79a5e6"><i class="layui-icon layui-icon-down"></i>显示全部信息</button>
              </div>



              <div id="showMoreDIV" style="display: none">

                  <div class="layui-form-item">
                      <label class="layui-form-label">开户行所在省</label>
                      <div class="layui-input-inline">
                          <input type="text" id="province" disabled="disabled" class="layui-input">
                      </div>
                      <label class="layui-form-label">开户行所在市</label>
                      <div class="layui-input-inline">
                          <input type="text" id="city" disabled="disabled" class="layui-input">
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label class="layui-form-label">开户行名称</label>
                      <div class="layui-input-inline">
                          <input type="text" id="bankName" disabled="disabled" class="layui-input">
                      </div>
                      <label class="layui-form-label">开户网点名称</label>
                      <div class="layui-input-inline">
                          <input type="text" id="bankNetName" disabled="disabled" class="layui-input">
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label class="layui-form-label">联行号</label>
                      <div class="layui-input-inline">
                          <input type="text" id="bankNumber" disabled="disabled" class="layui-input">
                      </div>
                      <label class="layui-form-label">银行代码</label>
                      <div class="layui-input-inline">
                          <input type="text" id="bankCode" disabled="disabled" class="layui-input">
                      </div>
                  </div>

                  <div class="layui-form-item">
                      <label class="layui-form-label">代付金额(元)</label>
                      <div class="layui-input-inline">
                          <input type="text" id="amount" disabled="disabled" class="layui-input">
                      </div>
                      <label class="layui-form-label">扣减金额(元)</label>
                      <div class="layui-input-inline">
                          <input type="text" id="subAmount" disabled="disabled" class="layui-input">
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label class="layui-form-label">扣减资金来源</label>
                      <div class="layui-input-inline">
                          <input type="text" id="subAmountFrom" disabled="disabled" class="layui-input">
                      </div>
                      <label class="layui-form-label">账户属性</label>
                      <div class="layui-input-inline">
                          <input type="text" id="accountAttr" disabled="disabled" class="layui-input">
                      </div>
                  </div>


                  <div class="layui-form-item">
                      <label class="layui-form-label">代付订单号</label>
                      <div class="layui-input-inline">
                          <input type="text" id="agentpayOrderId" disabled="disabled" class="layui-input">
                      </div>
                      <label class="layui-form-label">商户单号</label>
                      <div class="layui-input-inline">
                          <input type="text" id="mchOrderNo" disabled="disabled" class="layui-input">
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label class="layui-form-label">代付批次号</label>
                      <div class="layui-input-inline">
                          <input type="text" id="batchNo" disabled="disabled" class="layui-input">
                      </div>
                      <label class="layui-form-label">商户ID</label>
                      <div class="layui-input-inline">
                          <input type="text" id="mchId" disabled="disabled" class="layui-input">
                      </div>
                  </div>

                  <div class="layui-form-item">
                      <label class="layui-form-label">转账订单号</label>
                      <div class="layui-input-inline">
                          <input type="text" id="transOrderId" disabled="disabled" class="layui-input">
                      </div>
                      <label class="layui-form-label">状态</label>
                      <div class="layui-input-inline">
                          <input type="text" id="status" disabled="disabled" class="layui-input">
                      </div>
                  </div>

                  <div class="layui-form-item">
                      <label class="layui-form-label">客户端IP</label>
                      <div class="layui-input-inline">
                          <input type="text" id="clientIp" disabled="disabled" class="layui-input">
                      </div>
                      <label class="layui-form-label">设备</label>
                      <div class="layui-input-inline">
                          <input type="text" id="device" disabled="disabled" class="layui-input">
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label class="layui-form-label">通知地址</label>
                      <div class="layui-input-inline">
                          <input type="text" id="notifyUrl" disabled="disabled" class="layui-input">
                      </div>
                      <label class="layui-form-label">备注</label>
                      <div class="layui-input-inline">
                          <input type="text" id="remark" disabled="disabled" class="layui-input">
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label class="layui-form-label">通道ID</label>
                      <div class="layui-input-inline">
                          <input type="text" id="passageId" disabled="disabled" class="layui-input">
                      </div>
                      <label class="layui-form-label">创建时间</label>
                      <div class="layui-input-inline">
                          <input type="text" id="createTime" disabled="disabled" class="layui-input">
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label class="layui-form-label">更新时间</label>
                      <div class="layui-input-inline">
                          <input type="text" id="updateTime" disabled="disabled" class="layui-input">
                      </div>
                  </div>

              </div>

              <fieldset class="layui-elem-field">
                  <legend><button class='layui-btn layui-btn-xs layui-btn-danger'>选择打款方式</button></legend>

                  <div class="layui-form-item" style="margin-top: 20px; margin-bottom: 20px; margin-left: 30px">
                      <div class="layui-input-inline" id="choosePayTypeRadioDIV" style="width:80%!important;">
                      </div>
                  </div>

                  <fieldset class="layui-elem-field" id="choosePayTypeDiv1">
                      <legend><button class='layui-btn layui-btn-xs layui-btn-normal'>选择一种代付通道</button></legend>
                      <div class="layui-form-item" style="margin-top: 20px">
                          <label class="layui-form-label">代付通道</label>
                          <div class="layui-input-inline" >
                              <select name="confirmAgentpayPassageId" id="confirmAgentpayPassageId" lay-filter="agentpayPassageFilter" disabled>
                                  <option value="">选择代付通道</option>
                              </select>
                          </div>

                          <div class="layui-input-inline" style="padding-left: 50px" ><a id="useOtherPasserBtn" class="layui-btn layui-btn-sm layui-btn-warm"><i class="layui-icon layui-icon-about"></i>使用其他通道/银行卡完成代付</a>
                          </div>
                      </div>
                      <div class="layui-form-item">
                          <label class="layui-form-label">通道子账户</label>
                          <div class="layui-input-inline" >
                              <select name="confirmAgentpayPassageAccountId" id="confirmAgentpayPassageAccountId" lay-filter="agentpayPassageAccountFilter" disabled>
                                  <option value="">选择通道子账户</option>
                              </select>
                          </div>
                      </div>
                      <div class="layui-form-item layui-hide" id="confirmTccardAccountNoDIV" >
                          <label class="layui-form-label">选择出款银行卡</label>
                          <div class="layui-input-inline" >
                              <select name="confirmTccardAccountNo" id="confirmTccardAccountNo" lay-filter="confirmTccardAccountNoFilter" disabled>
                                  <option value="">选择出款银行卡</option>
                              </select>
                          </div>
                          <div class="layui-input-inline" style="padding-left: 50px" ><a id="setTopTccardBtn" class="layui-btn layui-btn-sm layui-btn-primary layui-hide"><i class="layui-icon layui-icon-up"></i>设置当前银行卡置顶</a></div>
                      </div>

                  </fieldset>

                  <fieldset class="layui-elem-field layui-hide" id="choosePayTypeDiv2">
                      <legend><button class='layui-btn layui-btn-xs layui-btn-normal'>选择多张银行卡累加打款</button></legend>

                      <div class="layui-form-item" style="margin-top: 20px">
                          <div style="margin-left: 40px;">
                              <p style="color: red; margin-top: 10px"> * 该打款方式将不影响当前商户的代付订单费率、费用， 有可能造成费率不一致的情况！</p>
                          </div>
                      </div>

                      <table class="layui-table">
                          <thead>
                          <tr><th>选择</th><th>卡号</th><th>账户名</th><th>银行名称</th><th>账户余额</th><th>状态</th><th>打款金额（元）</th></tr>
                          </thead>
                          <tbody id="tccardTBody"></tbody>
                      </table>
                      <button id="loadMoreCardDataBtn" class="layui-btn layui-btn-normal" style="width: 100%; background-color: #79a5e6">加载更多</button>

                  </fieldset>

                  <fieldset class="layui-elem-field layui-hide" id="choosePayTypeDiv3">
                      <legend><button class='layui-btn layui-btn-xs layui-btn-normal'>其他支付方式</button></legend>

                      <div class="layui-form-item" style="margin-top: 20px">
                          <div class=""  style="margin-left: 40px;">
                              <p style="color: #ff0000">请注意：  若选择其他方式给商户打款请选择该打款方式。 点击[审核通过]不会调用任何接口或银行卡，直接更改代付状态为成功！</p>
                              <p style="color: red; margin-top: 10px; margin-left: 53px"> * 该打款方式将不影响当前商户的代付订单费率、费用， 有可能造成费率不一致的情况！</p>
                          </div>
                      </div>


                  </fieldset>

              </fieldset>

              <div id="confirmButtonDIV" style="padding-left: 40px; margin-top: 50px">
                  <a class="layui-btn layui-btn-normal" id="auditOKBtn"><i class="layui-icon layui-icon-about"></i>审核通过，完成代付</a>
                  <a class="layui-btn layui-btn-danger" id="auditRejectBtn"><i class="layui-icon layui-icon-about"></i>审核拒绝，解除商户冻结金额</a>
                  <a class="layui-btn" style="display: none" id="giveUpBtn"><i class="layui-icon layui-icon-about"></i>放弃订单</a>
              </div>
          </div>
      </div>
    </div>
  </div>
</div>
<script>
    layui.use(['admin', 'form', 'table'],function(){
        var form = layui.form
        ,$ = layui.$
        ,admin = layui.admin
        ,element = layui.element
        ,view = layui.view
        ,table = layui.table
        ,layer = layui.layer ;
        // 导航
        element.render('breadcrumb', 'breadcrumb');
        var agentpayOrderId = view.getOpenParams('agentpayOrderId');

        var thisPassageId = null;  //当前的通道ID
        var thisPassageAccountId = null;  //当前的通道子账号ID
        var thisTccardAccountNo = null;  //银行卡ID
        var thisMchId = null;  //当前商户ID

        var currentPageIndex = 0;  //转卡通道银行卡相关数据
        var listPageSize = 10;

        var allPassage = {}; //所有的该商户的代付通道 （key agentpayPassageList v = obj ）

        //查询代付信息
        admin.req({
            type: 'get',
            url: layui.setter.baseUrl + '/agentpay/get',
            data: {agentpayOrderId : agentpayOrderId},
            error: function(err){layer.alert(JSON.stringify(err.field), {title: '错误提示'})},
            success: function(res){
                if(res.code == 0){
                    $('#agentpayOrderId').val(res.data.agentpayOrderId);
                    $('#mchOrderNo').val(res.data.mchOrderNo);
                    $('#batchNo').val(res.data.batchNo);
                    $('#mchId').val(res.data.mchId);
                    $('#amount').val(res.data.amount/100);
                    $('#fee').val(res.data.fee/100);
                    $('#remitAmount').val(res.data.remitAmount/100);
                    $('#subAmount').val(res.data.subAmount/100);
                    $('#passageId').val(res.data.passageId);
                    $('#accountAttr').val(res.data.accountAttr == 0 ? "对私" : res.data.accountAttr == 1 ? "对公" : "");
                    $('#accountName').val(res.data.accountName);
                    $('#accountNo').val(res.data.accountNo);
                    $('#transOrderId').val(res.data.transOrderId);
                    $('#status').val(res.data.status ==0?"待处理":res.data.status ==1?"处理中":res.data.status ==2?"成功":res.data.status ==4?"待审核":res.data.status ==3?"失败 ("+ (res.data.transMsg == null ? "" : res.data.transMsg)  + ")" :"未知状态");
                    $('#province').val(res.data.province);
                    $('#city').val(res.data.city);
                    $('#bankName').val(res.data.bankName);
                    $('#bankNetName').val(res.data.bankNetName);
                    $('#bankNumber').val(res.data.bankNumber);
                    $('#bankCode').val(res.data.bankCode);
                    $('#clientIp').val(res.data.clientIp);
                    $('#device').val(res.data.device);
                    $('#notifyUrl').val(res.data.notifyUrl);
                    $('#remark').val(res.data.remark);
                    $('#subAmountFrom').val(res.data.subAmountFrom ==1? "收款账户" : res.data.subAmountFrom ==2? "代付余额账户" : "未知");
                    if(res.data.createTime != "" && res.data.createTime != null) {
                        $('#createTime').val(layui.util.toDateString(res.data.createTime));
                    }
                    if(res.data.updateTime != "" && res.data.updateTime != null) {
                        $('#updateTime').val(layui.util.toDateString(res.data.updateTime));
                    }

                    thisPassageId = res.data.passageId;  //当前的通道ID
                    thisPassageAccountId = res.data.passageAccountId;  //当前的通道子账号ID
                    thisTccardAccountNo = res.data.tccardAccountNo;  //银行卡ID
                    thisMchId = res.data.mchId;
                    if(res.data.displayGiveUp == 1) {
                        $("#giveUpBtn").css("display", "");
                    }

                    //查询商户的所有通道配置项（同步）
                    admin.req({
                        type: 'post',
                        url: layui.setter.baseUrl + '/mch_agentpay_passage/list',
                        data: {mchId: thisMchId, limit: 1000}, //查询全部数据
                        error: function(err){layer.alert(err);},
                        success: function(passageRes){
                            if(passageRes.code == 0){
                                var agentpayPassageList = passageRes.data;
                                //遍历赋值
                                for(var i = 0; i < agentpayPassageList.length ; i++ ){

                                    if(agentpayPassageList[i].status != 1){
                                        continue; //状态为关闭状态
                                    }

                                    let feeStr = "";
                                    if(agentpayPassageList[i].mchFeeType == 1){ //费率
                                        feeStr = " [商户费率："+ agentpayPassageList[i].mchFeeRate + "]";
                                    }else if(agentpayPassageList[i].mchFeeType == 2){ //单笔费用
                                        feeStr = " [商户费率："+ agentpayPassageList[i].mchFeeEvery/100 + "元/笔]";

                                    }else if(agentpayPassageList[i].mchFeeType == 3){ //费率 +费用
                                        feeStr = " [商户费率："+ agentpayPassageList[i].mchFeeRate + "%+"+agentpayPassageList[i].mchFeeEvery/100+"元/笔]";
                                    }

                                    $("#confirmAgentpayPassageId").append('<option data-ifTypeCode= ' + agentpayPassageList[i].ifTypeCode + ' value= '+agentpayPassageList[i].agentpayPassageId+'>'+agentpayPassageList[i].passageName + feeStr +'</option>');
                                    allPassage[agentpayPassageList[i].agentpayPassageId] = agentpayPassageList[i];
                                }

                                $("#confirmAgentpayPassageId option[value='"+thisPassageId+"']").prop('selected', true);  //选择当前的代付通道
                                form.render('select');



                                //重新加载子账号列表
                                resetAccountSelect(thisPassageId, thisPassageAccountId);

                                let ifTypeCode = $("#confirmAgentpayPassageId").find("option:selected").attr("data-ifTypeCode"); //atbpay  代付通道，只需选择通道子账户
                                //重新转卡通道银行卡列表
                                if (ifTypeCode != "atbpay") {
                                    // resetTccardSelect(thisPassageAccountId, thisTccardAccountNo); //使用 轮询的卡
                                    resetTccardSelect(thisPassageAccountId, 'firstVal'); //使用置顶的卡

                                    if(allPassage[thisPassageId].configType == 2){ //转卡通道
                                        $("#confirmTccardAccountNoDIV").removeClass("layui-hide");
                                    }
                                }

                            }
                        }
                    });
                    form.render();
                    $("#tccardTBody .layui-form-checkbox").remove(); //删除layui 美化checkbox
                }
            }
        });


        //加载更多 数据
        var loadMoreDataFunc = function(){

            admin.req({  //查询银行卡列表
                type: 'post',
                url: layui.setter.baseUrl + '/tccard_info/listByRelaWithAgentpay',
                data: {apaId: 0, page: ++currentPageIndex, limit: listPageSize}, //暂时查询全部数据
                error: function(err){layer.alert(err.msg,{title:"请求失败"})},
                success: function(res){
                    if(res.code == 0){

                        let allPage = 0;

                        if(res.count % listPageSize == 0){
                            allPage = res.count / listPageSize;
                        }else{
                            allPage = parseInt(res.count / listPageSize) + 1;
                        }

                        if(allPage <= 1){ //仅有一页数据
                            $("#loadMoreCardDataBtn").addClass('layui-hide');
                        }

                        if(currentPageIndex > 1 && currentPageIndex >= allPage){ //已加载完成全部数据    【首次不判断】
                            layer.msg("已加载完成全部数据！");
                            $("#loadMoreCardDataBtn").addClass('layui-hide');
                        }

                        $.each(res.data, function(){

                            let thisObj = this;
                            let statusStr = this.Status == 1? "正常":"禁用";
                            let isRela = this.isRela;  //是否选中
                            let checkedHtml = isRela ? "checked" : "";
                            let bodyHtml = `
                         <tr>
                            <td><input style="display: block;" type="checkbox" class="tccardRelaCheckbox" ${checkedHtml} accountNo = "${thisObj.AccountNo}"/></td>
                            <td>${thisObj.AccountNo}</td>
                            <td>${thisObj.AccountName}</td>
                            <td>${thisObj.BankName}</td>
                            <td class="balanceTD">${thisObj.Balance/100}</td>
                            <td>${statusStr}</td>
                            <td><input class="tccardAmountInput layui-input layui-input-inline" style="width: 130px !important;"></td>
                        </tr>
                        `;

                            $("#tccardTBody").append(bodyHtml);
                        });

                        form.render();
                        $("#tccardTBody .layui-form-checkbox").remove(); //删除layui 美化checkbox
                    }
                }
            });

        }

        $("#loadMoreCardDataBtn").click(function(){
            loadMoreDataFunc();
        });

        loadMoreDataFunc(); //初次调用

        $("#showMoreBtn").click(function(){
            $("#showMoreDIV").fadeIn();
            $("#showMoreBtn").addClass('layui-hide');
        });

        //重新加载子账号列表 select
        function resetAccountSelect(agentpayPassageId, selectVal){

            admin.req({
                type: 'post',
                url: layui.setter.baseUrl + '/config/common/agentpay_passage_account',
                data: {agentpayPassageId: agentpayPassageId},
                error: function(err){layer.alert(err);},
                success: function(res){
                    if(res.code == 0){
                        var agentpayPassageAccountList = res.data;
                        //遍历赋值
                        for(var i in agentpayPassageAccountList){
                            $("#confirmAgentpayPassageAccountId").append('<option class="optionItem" value= '+agentpayPassageAccountList[i].id+'>'+agentpayPassageAccountList[i].accountName+' [' + agentpayPassageAccountList[i].id + ']' +'</option>');
                        }

                        $("#confirmAgentpayPassageAccountId").find("option[value='"+selectVal+"']").prop("selected", true);
                        form.render('select');
                    }
                }
            });
        }

        //重新加载子账号列表 select
        function resetTccardSelect(apaId, selectVal){

            admin.req({
                type: 'post',
                url: layui.setter.baseUrl + '/tccard_info/agentpayRelaedCardList',
                data: {apaId: apaId},
                error: function(err){layer.alert(err);},
                success: function(res){
                    if(res.code == 0){
                        var cardList = res.data;
                        //遍历赋值
                        for(var i = 0 ; i <cardList.length; i++ ){
                            var cardItem = cardList[i];
                            $("#confirmTccardAccountNo").append(`<option class="optionItem" value='${cardItem.accountNo}'> ${cardItem.bankName} | ${cardItem.accountName} | ${cardItem.accountNo} | 余额：${cardItem.balance / 100}元</option>`);
                        }

                        //判断是否显示 置顶按钮
                        if(cardList.length > 0){
                            $("#setTopTccardBtn").removeClass('layui-hide');
                        }else{
                            $("#setTopTccardBtn").addClass('layui-hide');
                        }

                        if('firstVal' == selectVal && cardList.length > 0){ //默认第一个选中
                            $("#confirmTccardAccountNo").find("option[value='"+cardList[0].accountNo+"']").prop("selected", true);
                        }else{
                            $("#confirmTccardAccountNo").find("option[value='"+selectVal+"']").prop("selected", true);
                        }

                        form.render('select');
                    }
                }
            });
        }

        //监听[选择代付通道]选择事件
        form.on('select(agentpayPassageFilter)',function(data){
            let ifTypeCode = $(data.elem).find("option:selected").attr("data-ifTypeCode");

            //清空 子账号
            $("#confirmAgentpayPassageAccountId").find('option.optionItem').remove();
            //清空 银行卡列表
            $("#confirmTccardAccountNo").find('option.optionItem').remove();

            //根据类型隐藏 银行卡
            if(allPassage[data.value].configType == 1 || ifTypeCode == "atbpay"){ //内置接口方式
                $("#confirmTccardAccountNoDIV").addClass("layui-hide");
            }else{
                $("#confirmTccardAccountNoDIV").removeClass("layui-hide");
            }

            //重新加载子账号
            resetAccountSelect(data.value, null);
            form.render('select');
        });

        //监听[选择代付通道子账号]选择事件
        form.on('select(agentpayPassageAccountFilter)',function(data){

            //清空 银行卡列表
            $("#confirmTccardAccountNo").find('option.optionItem').remove();

            if(!$("#confirmTccardAccountNoDIV").hasClass("layui-hide")){ //需要重新加载银行卡
                resetTccardSelect(data.value, null);
            }
            form.render('select');

        });

        $("#useOtherPasserBtn").click(function(){

            layer.confirm("请注意： 选择其他支付通道/银行卡将不影响当前商户的代付订单费率、费用， 有可能造成费率不一致的情况！", function(layIndex){

                $("#confirmAgentpayPassageId").removeAttr('disabled');
                $("#confirmAgentpayPassageAccountId").removeAttr('disabled');
                $("#confirmTccardAccountNo").removeAttr('disabled');
                form.render('select');

                $("#useOtherPasserBtn").addClass('layui-hide');
                layer.close(layIndex);
            });
        });

        //审核通过 点击事件
        $("#auditOKBtn").click(function(){

            let choosePayType = $("input[name='choosePayType']:checked").val();

            if(!choosePayType){
                return layer.alert("请选择打款方式！");
            }

            var reqData = {
                choosePayType: choosePayType,  //打款方式
                agentpayOrderId: agentpayOrderId,   //代付订单号
                confirmPassageId: null,   //选择的通道
                confirmApaId: null,   //选择的子账号
                confirmTccardAccountNo: null,  //选择的银行卡
                multipleCardListStr: ""  //多张卡累加打款 JSON串
                };

            let confirmPassageId = $("#confirmAgentpayPassageId").val();

            if(!confirmPassageId){
                return layer.alert("请选择代付通道！");
            }

            if(choosePayType == 1){ //选择一种通道、银行卡

                let confirmApaId = $("#confirmAgentpayPassageAccountId").val();

                if(!confirmApaId){
                    return layer.alert("请选择代付通道子账号！");
                }

                let ifTypeCode = $("#confirmAgentpayPassageId").find("option:selected").attr("data-ifTypeCode"); //atbpay  代付通道，只需选择通道子账户
                let confirmTccardAccountNo = $("#confirmTccardAccountNo").val() || ""; //如果没选择则默认空串， 避免 银行卡 ---》 接口方式， 存在脏数据

                if(allPassage[confirmPassageId].configType == 2 && !confirmTccardAccountNo && ifTypeCode != "atbpay"){
                    return layer.alert("请选择转卡银行卡！");
                }

                reqData.confirmPassageId = confirmPassageId;
                reqData.confirmApaId = confirmApaId;
                reqData.confirmTccardAccountNo = confirmTccardAccountNo;


            }else if(choosePayType == 2){ //多张银行卡

                let cardArray = [];
                var allAmount = 0;

                let accountCheckboxList = $("#tccardTBody .tccardRelaCheckbox:checked");
                for(let i = 0 ; i< accountCheckboxList.length; i++){

                    let thisAccountNo = accountCheckboxList.eq(i).attr('accountNo');
                    let thisAmount = accountCheckboxList.eq(i).parent().parent().find('.tccardAmountInput').val();
                    let thisBalance = accountCheckboxList.eq(i).parent().parent().find('.balanceTD').text();


                    if(!thisAccountNo){
                        return layer.alert("请选择银行卡！");
                    }
                    if(!thisAmount || isNaN(thisAmount) || thisAmount <= 0 ){
                        return layer.alert("请输入正确的金额！");
                    }

                    if( (thisAmount * 1) > (thisBalance * 1) ){
                        return layer.alert("打款金额不得高于当前账户余额！");
                    }

                    cardArray.push({accountNo: thisAccountNo, amount: thisAmount});
                    allAmount += ( thisAmount * 1 );
                }

                if(cardArray.length <= 0){
                    return layer.alert("请选择转卡银行卡！");
                }

                if( ($('#remitAmount').val() * 1) !=  allAmount){
                    return layer.alert("代付金额与选择的银行卡打款总金额不一致， 请更改！");
                }

                reqData.multipleCardListStr = JSON.stringify(cardArray);

            }else if(choosePayType == 3){ //直接更新为成功

            }

            layer.confirm("确认审核通过，此操作将发起代付！", function(layIndex){
                layer.close(layIndex);
                var loadIndex = layer.msg('请稍后...', {icon: 16,shade: 0.4,time: 9999999999});

                admin.req({
                    type: 'post',
                    url: layui.setter.baseUrl + '/agentpay/auditOK',
                    data: reqData,
                    error: function(err){layer.alert(err);},
                    success: function(res){
                        if(res.code == 0){

                            layer.msg("处理完成", {icon:1,time:1000},function(){
                                layer.closeAll();
                                table.reload('tableReload');
                            });
                        }
                    },
                    complete: function(){
                        layer.close(loadIndex);
                    }
                });

            });

        });

        //审核拒绝 点击事件
        $("#auditRejectBtn").click(function(){

            layer.confirm("确认审核拒绝， 将退还商户的冻结资金！", function(layIndex){
                layer.close(layIndex);
                var loadIndex = layer.msg('请稍后...', {icon: 16,shade: 0.4,time: 9999999999});

                admin.req({
                    type: 'post',
                    url: layui.setter.baseUrl + '/agentpay/auditReject',
                    data: {agentpayOrderId: agentpayOrderId},
                    error: function(err){layer.alert(err);},
                    success: function(res){
                        if(res.code == 0){
                            layer.msg("处理完成", {icon:1,time:1000},function(){
                                layer.closeAll();
                                table.reload('tableReload');
                            });
                        }
                    },
                    complete: function(){
                        layer.close(loadIndex);
                    }
                });
            });
        });

        //审核拒绝 点击事件
        $("#giveUpBtn").click(function(){

            layer.confirm("确认放弃该订单么！", function(layIndex){
                layer.close(layIndex);
                var loadIndex = layer.msg('请稍后...', {icon: 16,shade: 0.4,time: 9999999999});

                admin.req({
                    type: 'post',
                    url: layui.setter.baseUrl + '/agentpay/giveup',
                    data: {agentpayOrderId: agentpayOrderId},
                    error: function(err){layer.alert(err);},
                    success: function(res){
                        if(res.code == 0){
                            layer.msg(res.msg, {title: "提示", icon:1,time:1000},function(){
                                layer.closeAll();
                                table.reload('tableReload');
                            });
                        }
                    },
                    complete: function(){
                        layer.close(loadIndex);
                    }
                });
            });
        });

        function procChoosePayTypeDivFunc(val){

            $("#choosePayTypeDiv1").addClass("layui-hide");
            $("#choosePayTypeDiv2").addClass("layui-hide");
            $("#choosePayTypeDiv3").addClass("layui-hide");
            $("#choosePayTypeDiv99").addClass("layui-hide");

            $("#choosePayTypeDiv" + val).removeClass("layui-hide");

            $("#confirmButtonDIV").removeClass("layui-hide");
        }

        form.on("radio(choosePayTypeFilter)", function(data){
            procChoosePayTypeDivFunc(data.value);
        });

        var tplEditBySupplier = function(d){
            return "<a class='layui-btn layui-btn-xs layui-btn-warm' lay-event='selectedThis'><i class='layui-icon layui-icon-release'></i>转交</a>";
        };


        //查询支持的打款方式
        admin.req({
            type: 'get',
            url: layui.setter.baseUrl + '/agentpay/getAgentpayChoosePayTypeConfig',
            error: function(err){layer.alert(err);},
            success: function(res){
                if(res.code == 0){
                    var agentpayChoosePayTypeArray = JSON.parse(res.data.agentpayChoosePayType);
                    $(agentpayChoosePayTypeArray).each(function(){
                       if(this == 1){
                           $("#choosePayTypeRadioDIV").append(`<input type="radio" lay-filter="choosePayTypeFilter" name="choosePayType" value="1" title="选择一种代付通道">`);
                       }else if(this == 3){
                           $("#choosePayTypeRadioDIV").append(`<input type="radio" lay-filter="choosePayTypeFilter" name="choosePayType" value="3" title="其他支付方式">`);
                       }
                    });
                    $("#choosePayTypeRadioDIV input[lay-filter='choosePayTypeFilter']").eq(0).prop('checked', true);
                    procChoosePayTypeDivFunc($("#choosePayTypeRadioDIV input[lay-filter='choosePayTypeFilter']").eq(0).val());
                    form.render();
                    $("#tccardTBody .layui-form-checkbox").remove(); //删除layui 美化checkbox
                }
            }
        });


        //设置当前银行卡置顶
        $("#setTopTccardBtn").click(function(){

            let accountNo = $("#confirmTccardAccountNo").val();
            if(!accountNo){
                layer.alert("请选择银行卡！");
                return false;
            }

            var layerShadeId = layer.msg('请稍后...', {time: 0, shade: 0.1});
            admin.req({
                type: 'post',
                url: layui.setter.baseUrl + '/tccard_info/setTop',
                data: {accountNo: accountNo},
                error: function (err) {layer.alert(err);},
                success: function (res) {
                    if (res.code == '0') { //成功
                        layer.msg('成功', {time: 500});
                        //清空 银行卡列表
                        $("#confirmTccardAccountNo").find('option.optionItem').remove();
                        resetTccardSelect($("#confirmAgentpayPassageAccountId").val(), accountNo);
                    }
                }, complete:function(){
                    layer.close(layerShadeId);
                }
            });

        });


    })
</script>